package com.macro.mall.tiny.modules.pms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.macro.mall.tiny.modules.pms.model.PmsBrand;
import com.macro.mall.tiny.modules.pms.mapper.PmsBrandMapper;
import com.macro.mall.tiny.modules.pms.service.PmsBrandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 品牌表 服务实现类
 * </p>
 *
 * @author macro
 * @since 2024-08-15
 */
@Service
public class PmsBrandServiceImpl extends ServiceImpl<PmsBrandMapper, PmsBrand> implements PmsBrandService {

    @Override
    public Page<PmsBrand> list(String keyword, Integer pageSize, Integer pageNum) {
        Page<PmsBrand> page = new Page<>(pageNum, pageSize);
        QueryWrapper<PmsBrand> wrapper = new QueryWrapper<>();
        wrapper.lambda().like(keyword != null, PmsBrand::getName, keyword).or().like(keyword != null, PmsBrand::getFirstLetter, keyword);
        wrapper.lambda().orderByDesc(PmsBrand::getSort);
        return this.page(page, wrapper);
    }

    @Override
    @Transactional
    public boolean updateShowStatus(List<Long> ids, Integer showStatus) {
        UpdateWrapper<PmsBrand> wrapper = new UpdateWrapper<>();
        wrapper.lambda().in(PmsBrand::getId, ids).set(PmsBrand::getShowStatus, showStatus);
        return this.update(wrapper);
    }
}
